package MsgPackage;

/**
 * @author Omri Barda		039725890 
 * @author Amit Joseph		034608547
 * @author Gilad Shpigel  	300162393
 * @author Elad Elbaz		040539959
 * @version June 2012
 */

import java.util.ArrayList;
import java.util.HashMap;
import entities.Answer;
import entities.ComputerizedExam;
import entities.QuestionPerExam;
import entities.Student;

public class GetExamsPerStudentPack extends MessagePack {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Student stnd;
	private ArrayList<ComputerizedExam> comExmsLst;
	private HashMap<String, ArrayList<QuestionPerExam>> qstnPerExmLst;

	/**
	 * constructor
	 * 
	 * @param stnd
	 */
	public GetExamsPerStudentPack(Student stnd) {
		setStudent(stnd);
		this.op = OpType.GetExamsPerStudent;
	}

	/**
	 * @return the questions per exam
	 */
	public HashMap<String, ArrayList<QuestionPerExam>> getAllQsforExams() {
		return qstnPerExmLst;
	}

	/**
	 * 
	 * @param ExmsLst
	 *            to be added
	 */
	public void addExams(ArrayList<ComputerizedExam> ExmsLst) {
		if (comExmsLst == null)
			comExmsLst = new ArrayList<ComputerizedExam>();
		comExmsLst.addAll(ExmsLst);
	}

	/**
	 * 
	 * @param Exm
	 *            to be added
	 */
	public void addExam(ComputerizedExam Exm) {
		if (comExmsLst == null)
			comExmsLst = new ArrayList<ComputerizedExam>();
		comExmsLst.add(Exm);
	}

	/**
	 * 
	 * @param examCode
	 *            of the exam
	 * @param qstPerExm
	 *            the questions to be added
	 */
	public void addQuestionPerExam(String examCode,
			ArrayList<QuestionPerExam> qstPerExm) {
		if (qstnPerExmLst == null)
			qstnPerExmLst = new HashMap<String, ArrayList<QuestionPerExam>>();
		ArrayList<QuestionPerExam> temp;
		if ((temp = qstnPerExmLst.get(examCode)) == null)
			temp = new ArrayList<QuestionPerExam>();
		temp.addAll(qstPerExm);
		qstnPerExmLst.put(examCode, temp);
	}

	/**
	 * 
	 * @param examCode
	 *            of the exam
	 * @param qstPerExm
	 *            the question to be added
	 */
	public void addQuestionPerExam(String examCode, QuestionPerExam qstPerExm) {
		if (qstnPerExmLst == null)
			qstnPerExmLst = new HashMap<String, ArrayList<QuestionPerExam>>();
		ArrayList<QuestionPerExam> temp;
		if ((temp = qstnPerExmLst.get(examCode)) == null)
			temp = new ArrayList<QuestionPerExam>();
		temp.add(qstPerExm);
		qstnPerExmLst.put(examCode, temp);
	}

	/**
	 * 
	 * @param examCode
	 *            of the exam
	 * @param index
	 *            of the exam
	 * @return the selected question of the exam
	 */
	public QuestionPerExam getQuestion(String examCode, int index) {
		return qstnPerExmLst.get(examCode).get(index);
	}

	/**
	 * 
	 * @param examCode
	 *            of the exam
	 * @return the exam questions
	 */
	public ArrayList<QuestionPerExam> getQuestions(String examCode) {
		return qstnPerExmLst.get(examCode);
	}

	/**
	 * 
	 * @param index
	 *            of selected exam
	 * @return the exam (computerized)
	 */
	public ComputerizedExam getComputerizedExam(int index) {
		return comExmsLst.get(index);
	}

	/**
	 * @return the comExmsLst
	 */
	public ArrayList<ComputerizedExam> getComputerizedExams() {
		return comExmsLst;
	}

	/**
	 * 
	 * @return the computerized exam size
	 */
	public int ComputerizedExamSize() {
		return comExmsLst.size();
	}

	/**
	 * 
	 * @param ansLst
	 *            to be added in the exam
	 * @param index
	 *            in the exam list
	 */
	public void insertAnswers(ArrayList<Answer> ansLst, int index) {
		comExmsLst.get(index).setAnswers(ansLst);
	}

	/**
	 * @return the Student
	 */
	public Student getStudent() {
		return stnd;
	}

	/**
	 * @param stnd
	 *            the Student to set
	 */
	public void setStudent(Student stnd) {
		this.stnd = stnd;
	}

}
